﻿using System;
using System.Collections.Generic;
using YJKRevitBase.Math;
using YJKRevitDimensionText.VerticalAutoDim.GeoModel;

namespace YJKRevitDimensionText.VerticalAutoDim.Comparer
{
	internal class GeoComparerByTopLevel : IComparer<IPlanarGeo>
	{
		public GeoComparerByTopLevel(bool bByBottom = false)
		{
			this.IsByBottom = bByBottom;
		}

		public int Compare(IPlanarGeo x, IPlanarGeo y)
		{
			double num;
			if (this.IsByBottom)
			{
				num = x.BottomElev - y.BottomElev;
			}
			else
			{
				num = x.TopElev - y.TopElev;
			}
			if (MathUtility.IsEqual(num, 0.0))
			{
				return 0;
			}
			if (MathUtility.GreaterThan(num, 0.0))
			{
				if (this.IsByBottom)
				{
					return -1;
				}
				return 1;
			}
			else
			{
				if (this.IsByBottom)
				{
					return 1;
				}
				return -1;
			}
		}

		protected readonly bool IsByBottom;
	}
}
